package net.NingXiaRuiTai.ShortChain.config;

import lombok.extern.slf4j.Slf4j;
import net.NingXiaRuiTai.ShortChain.enums.BizCodeEnum;
import net.NingXiaRuiTai.ShortChain.exception.BizeException;
import org.springframework.context.annotation.Configuration;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;



@Slf4j
@Configuration
public class SnowFlakeWordIdConfig {
    static {
        try {
            InetAddress localHost = Inet4Address.getLocalHost();
            String hostAddress = localHost.getHostAddress();
            String workId=Math.abs(hostAddress.hashCode())%1024+ "";
            System.setProperty("workId",workId);
            log.info("当前机器的workId:{}",workId);
        } catch (UnknownHostException e) {
            throw new BizeException(BizCodeEnum.OPS_NETWORK_ADDRESS_ERROR);
        }
    }
}
